package com.zhijian.medical.config.datasource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

/**
 * JdbcTemplate多数据源配置，依赖于数据源配置
 *
 * @author HCG
 * @version 1.0
 * @date 2021/8/31
 */
@Configuration
public class JdbcTemplateDataSourceConfig {

    /**
     * JdbcTemplate数据源，local
     *
     * @param dataSource
     * @return
     */
    @Primary
    @Bean(name = "localJdbcTemplate")
    public JdbcTemplate localJdbcTemplate(@Qualifier("localDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

    /**
     * JdbcTemplate数据源，remote
     *
     * @param dataSource
     * @return
     */
    @Primary
    @Bean(name = "remoteJdbcTemplate")
    public JdbcTemplate remoteJdbcTemplate(@Qualifier("remoteDataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }

}
